// Copyright 2007-2009, Stanford University. All Rights Reserved.
// Copyright 2010-2011, Dependable Systems Lab, EPFL. All Rights Reserved.
// Copyright 2012, Google Inc. All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimers.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimers
// in the documentation and/or other materials provided with the
// distribution.
//     * Neither the names of the klee Team, Stanford University, nor the
// names of its contributors may be used to endorse or promote
// products derived from the software without specific prior
// written permission. Neither the names of the Dependable Systems
// Laboratory, EPFL, nor the names of its contributors may be used to
// endorse or promote products derived from the software without prior
// written permission. Neither the names of Google Inc. nor the names of
// its contributors may be used to endorse or promote products derived from
// the software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef SRC_EXPR_EXPRPPRINTER_H_
#define SRC_EXPR_EXPRPPRINTER_H_

#include "expr/Expr.h"

namespace seven_summits {
namespace expr {

class ConstraintManager;

class ExprPPrinter {
protected:
  ExprPPrinter() {}

public:
  static ExprPPrinter *create(std::ostream &os);

  virtual ~ExprPPrinter() {}

  virtual void setNewline(const std::string &newline) = 0;
  virtual void reset() = 0;
  virtual void scan(const ref<Expr> &e) = 0;
  virtual void print(const ref<Expr> &e, unsigned indent=0) = 0;

  // utility methods

  template<class Container>
  void scan(Container c) {
    scan(c.begin(), c.end());
  }

  template<class InputIterator>
  void scan(InputIterator it, InputIterator end) {
    for (; it!=end; ++it)
      scan(*it);
  }

  /// printOne - Pretty print a single expression prefixed by a
  /// message and followed by a line break.
  static void printOne(std::ostream &os, const char *message,
                       const ref<Expr> &e);

  /// printSingleExpr - Pretty print a single expression.
  ///
  /// The expression will not be followed by a line break.
  ///
  /// Note that if the output stream is not positioned at the
  /// beginning of a line then printing will not resume at the
  /// correct position following any output line breaks.
  static void printSingleExpr(std::ostream &os, const ref<Expr> &e);

  static void printConstraints(std::ostream &os,
                               const ConstraintManager &constraints);

  static void printQuery(std::ostream &os,
                         const ConstraintManager &constraints,
                         const ref<Expr> &q,
                         const ref<Expr> *evalExprsBegin = 0,
                         const ref<Expr> *evalExprsEnd = 0,
                         const Array * const* evalArraysBegin = 0,
                         const Array * const* evalArraysEnd = 0,
                         bool printArrayDecls = true);
};

}  // namespace xpr
}  // namespace seven_summits

#endif  // SRC_EXPR_EXPRPPRINTER_H_
